package gui.catalogues.telephones.models;

import java.util.List;

import javax.swing.table.AbstractTableModel;

import model.Telephone;

public class TelephonesTableModel extends AbstractTableModel {
	private List<Telephone> elementsList;
	private String[] colNames = {"Id", "Tipo", "Teléfono"};

	public void setElementList(List<Telephone> elementList) {
		this.elementsList = elementList;
	}
	
	/* (non-Javadoc)
	 * @see javax.swing.table.AbstractTableModel#getColumnName(int)
	 */
	@Override
	public String getColumnName(int column) {
		//return super.getColumnName(column);
		// reloaded to:
		return colNames[column];
	}

	@Override
	public int getRowCount() {
		try {
			return elementsList.size();
		} catch (Exception e) {
			//System.out.println("Exception@Telephones.TableModel.getRowCount: " + e);
		} 
		return 0;
	}

	@Override
	public int getColumnCount() {
//		System.out.println("PersonTableModel.getColumnCount puede tronar. colCount = " + colNames.length);
		return colNames.length;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Telephone elementItem = elementsList.get(rowIndex);
		switch (columnIndex) {
		case 0:
			return elementItem.getId();
		case 1:
			return elementItem.getIdType();
		case 2:
			return elementItem.getDesc();
		default:
			return null;
		}
	}
}
